Distinguish between null and unspecified selectors #254
+58
−20
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
To reduce latency and type proliferation, a generic siteselector that gets applied to a lattice becomes an
AppliedSiteSelector
with minimal type parameters. That means that e.g.cells
, which can be many things becomes aVector{SVector{L,Int}}
. Ifcells
was not specified (it wasmissing
), it becomes an emptyVector{SVector{L,Int}}
. The codebase knows that if it encounters an empty appliedcells
, this means "unconstrained" cells. The other option was to introduceUnion{Vector{SVector{L,Int}}, Missing}
, which I don't trust to always behave under type inference, so it was discarded.The problem comes when one passes a function to cells,
cells = n -> is_cell_in_subset(n)
for example. If that ends up empty upon application to lattice, we currently don't distinguish this from the unconstrainedcells=missing
case. This causes bugs in corner cases in different places. One particular exampleThis
h
should be zero, but before this PR it is not, because an emptysublats::Vector{Int}
results after application, which is indistinguishable fromsublats = missing
(or simply absentsublats
) above.The solution taken in this PR is to make
AppliedSiteSelector
andAppliedHopSelector
know if they are an empty selector by adding anisnull
field that is checked before everything else. Therefore, an empty appliedcells
that does not come fromcells = missing
will causeisnull == true
, and the selector will behave as expected. The solution is quite minimal and has no performance or complexity drawbacks.